package ptij.vocoder.baseModel.closed_loop;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.Token;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// Convolve
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class Convolve extends TypedAtomicActor {

    public Convolve(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        x = new TypedIOPort(this, "x", true, false);
        x.setTypeEquals(BaseType.OBJECT);

        h = new TypedIOPort(this, "h", true, false);
        h.setTypeEquals(BaseType.OBJECT);

        y = new TypedIOPort(this, "y", false, true);
        y.setTypeEquals(BaseType.OBJECT);
        
        txdtx_ctrl = new TypedIOPort(this, "txdtx_ctrl", true, false);
        txdtx_ctrl.setTypeEquals(BaseType.OBJECT);
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort x;
    public TypedIOPort h;
    public TypedIOPort txdtx_ctrl;

    // Output Ports
    public TypedIOPort y;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
    }

    public void fire() throws IllegalActionException {
        ObjectToken obj = (ObjectToken) txdtx_ctrl.get(0);
        Short txdtx = (Short) obj.getValue();
        if((txdtx.shortValue() & Cnst.TX_SP_FLAG) != 0) {
            obj = (ObjectToken) x.get(0);
            Short [] arg1 = (Short []) obj.getValue();
    
            obj = (ObjectToken) h.get(0);
            Short [] arg2 = (Short []) obj.getValue();
    
            Short [] res = _convolut(arg1, arg2);
            y.broadcast(new ObjectToken(res));
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private Short [] _convolut(Short [] arg1, Short [] arg2) {
        Short [] res = new Short[Cnst.L_SUBFR];

        return res;
    }
    
    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////

}
